//
//  MomentsTableViewCell.m
//  AnimationRecommend
//
//  Created by 花花蔡 on 2017/2/22.
//  Copyright © 2017年 ljm. All rights reserved.
//

#import "MomentsTableViewCell.h"
#import "MomentsBodyView.h"
#import "MomentsToolBarView.h"

@interface MomentsTableViewCell ()

@property(nonatomic,strong) MomentsBodyView *bodyView;
@property(nonatomic,strong) MomentsToolBarView *toolBarView;


@end

@implementation MomentsTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
}


+ (instancetype)loadTableViewCellWithTableView:(UITableView *)tableView {
    
    static NSString *cell_ID = @"MomentsCell_ID";
    MomentsTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cell_ID];
    if (!cell) {
        cell = [[MomentsTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cell_ID];
    }
    return cell;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    
    if (self = [super initWithStyle:style reuseIdentifier: reuseIdentifier]) {
        //设置UI
        // 阴影
        self.layer.shadowOffset = CGSizeMake(0, 1);  //阴影偏移量
        self.layer.shadowRadius = 1.5;
        self.layer.shadowColor = [UIColor grayColor].CGColor;
        self.layer.shadowOpacity = 1; //阴影透明度
        // 圆角
        self.layer.cornerRadius = 7.0;
        self.layer.masksToBounds = NO;
        
        [self setBodyView];

    }
    return  self;
}

- (void)setBodyView {
    _bodyView = [[MomentsBodyView alloc] init];
    [self addSubview:_bodyView];
    _toolBarView = [[MomentsToolBarView alloc] initWithBtnClicked:^(id sender) {
        if (_delegate)  [_delegate cellBtnClick:sender];
    }];
    [self addSubview:_toolBarView];
}

- (void)setMomentVM:(MomentsViewModel *)momentVM {
    //设置子控件的frame
    self.bodyView.frame = momentVM.momentsBodyFrame;
    self.bodyView.momentFrames = momentVM;
    self.toolBarView.frame = momentVM.momentsToolBarFrame;
    self.toolBarView.momentFrames = momentVM;
}
//设置cell的frame
-(void)setFrame:(CGRect)frame{
    frame.origin.x += bodyCellMargin;
    frame.size.width -= bodyCellMargin * 2;
    [super setFrame:frame];
}

@end
